package com.abbcc.service.impl;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.abbcc.common.CommonConst;
import com.abbcc.dao.LogDAO;
import com.abbcc.models.TdAdmin;
import com.abbcc.models.TdLog;
import com.abbcc.models.TdUser;
import com.abbcc.service.LogService;
import com.abbcc.util.BeansFactory;
import com.abbcc.util.ipUtil.IPSeeker;

@Service
public class LogServiceImpl extends ServiceImpl<TdLog,LogDAO> implements LogService{
	@Autowired
	private LogDAO logDAO;

	public void saveLog(String name, String desc, String logType,String isadmin) {
		HttpSession session = ServletActionContext.getRequest().getSession();
		TdUser user = (TdUser) session.getAttribute(CommonConst.SESSIONUSER);
		TdAdmin admin = (TdAdmin) session
				.getAttribute(CommonConst.SESSIONADMIN);
		     String ip = ServletActionContext.getRequest().getRemoteAddr();  
		//String ip = ServletActionContext.getRequest().getRemoteAddr();
		TdLog al = new TdLog();
		al.setAddTime(new Date());
		al.setIp(ip);
			al.setIsAdmin(isadmin);
			if(isadmin.equals("0"))
				if(user!=null)
					al.setUserId(user.getUserId());
			else
				if(admin!=null)
					al.setAdminId(admin.getAdminId());
		al.setName(name);
		al.setType(logType);
		al.setLdesc(desc);
		logDAO.save(al);
		
	}

}
